export default class UICtrl extends Laya.Script {

    constructor() { 
        super(); 
        /** @prop {name:txt_time, tips:"整数类型示例", type:Node, default:null}*/
        this.txt_time=null;
        /** @prop {name:txt_sence, tips:"整数类型示例", type:Node, default:null}*/
        this.txt_sence=null;
        /** @prop {name:gameover, tips:"整数类型示例", type:Node, default:null}*/
        this.gameover=null;
        this.score=0;
        this.time=30;
        this.isover=false;
        
        // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    }
    onAwake(){
        Laya.timer.loop(1000,this,this.addtime)
        Laya.stage.on("AddScore",this,this.addScore);
        Laya.stage.on("start",this,this.start);
        Laya.stage.on("gameover",this,function(){this.isover=true});
    }
    start(){
        this.isover=false;
        this.score=0;
        this.txt_sence.text="分数:"+this.score;
        this.time=30;
        this.txt_time.text="时间:"+this.time;
    }
    addScore(){
        if(this.isover)return;
        this.score++;
        this.txt_sence.text="分数:"+this.score;
    }
    addtime(){
        if(this.isover)return;
        this.time--;
        this.txt_time.text="时间:"+this.time;
        if(this.time<=0){
            Laya.stage.event("gameover")
        }
    }
}